package org.shuma.goods.controller;

import org.shuma.goods.commons.Result;
import org.shuma.goods.domain.DTO.SearchProductDTO;
import org.shuma.goods.service.ProductBasicInfoService;
import org.shuma.user.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/basic")
public class ProductBasicInfoController {

    @Autowired
    private ProductBasicInfoService productBasicInfoService;

    @PostMapping("/page")
    public Result getProductBasicInfoPage(
            @RequestParam(defaultValue = "0") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody SearchProductDTO searchProductDTO,
            @RequestAttribute("userInfo") UserVo userVo) {
        if(userVo == null) return Result.error("用户未登录");
        return Result.success(productBasicInfoService.getProductBasicInfoList(searchProductDTO,pageNum,pageSize,userVo));
    }

    @GetMapping("/status")
    public Result getProductStatus(@RequestParam("productCheckState") Integer productId,
                                   @RequestParam(defaultValue = "0") int pageNum,
                                   @RequestParam(defaultValue = "10") int pageSize,
                                   @RequestAttribute("userInfo")  UserVo userVo) {
        if(userVo == null) return Result.error("用户未登录");
        return Result.success(productBasicInfoService.getProductStatus(productId,pageNum,pageSize,userVo));
    }


}

